public class test1 {
    public List<Integer> preorderTraversal(TreeNode root) {
        List<Integer> res = new ArrayList<>();
        //前序：中左右
        preOrder(root,res);
        return res;
    }
    private void preOrder(TreeNode root,List<Integer> res){
        if(root==null){
            return;
        }
        res.add(root.val);

        preOrder(root.left,res);
        preOrder(root.right,res);
    }
}
